package com.jiepos.mpos.biz.review.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.jiepos.mpos.biz.affix.service.AppAffixInfService;
import com.jiepos.mpos.biz.customer.service.AppCustomerInfoService;
import com.jiepos.mpos.biz.customer.service.CustomBankcardInfoService;
import com.jiepos.mpos.biz.review.service.MemReviewService;
import com.jiepos.mpos.biz.review.service.SettleAccountService;
import com.jiepos.mpos.common.entity.App_Menu_CdEntity;
import com.jiepos.mpos.common.entity.MemReviewEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * 
 * 结算信息变更待办事项管理
 * @ProjectName:  [mpos] 
 * @Package com.jiepos.mpos.biz.review.controller 
 * @author 张磊
 * @version 1.0
 * @since 2017年9月26日 下午5:26:35
 * @history（历次修订内容、修订人、修订时间等）
 * @UpdateRemark [说明本次修改内容]
 * @Copyright (c) 2017 江苏杰博实信息技术有限公司
 */
@Controller
@RequestMapping("settleaccount")
public class SettleAccountController extends BaseController{
	
	@Autowired
	private SettleAccountService settleAccountService;
	
	@Autowired
	private AppCustomerInfoService appCustomerInfoService;
	
	@Autowired
	private CustomBankcardInfoService customBankcardInfoService;
	
	@Autowired
	private AppAffixInfService appAffixInfService;
	
	@Autowired
	private MemReviewService memReviewService;
	
	/**
	 * 跳转到列表页
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/jumpToSettleAccountReview.do")
	public ModelAndView jumpToSettleAccountReview(HttpServletRequest request, HttpServletResponse response){
		Map map=super.getLoginUser(request, response);
		App_Menu_CdEntity app_Menu_CdEntity = memReviewService.getMenuCode("settleaccount/getSettleAccountReviewList.do");
		map.put("menuCode", app_Menu_CdEntity.getMenu_uuid());
		return new ModelAndView(new RedirectView("getSettleAccountReviewList.do"), map);
	}
	
	/**
	 * 获取会员信息列表
	 * @param request
	 * @param response
	 * @param pagination
	 * @param memReviewEntity
	 * @return
	 */
	@RequestMapping("/getSettleAccountReviewList.do")
	public ModelAndView getSettleAccountReviewList(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination, MemReviewEntity memReviewEntity){
		ModelAndView model = new ModelAndView("/module/review/settleaccountreview/settleaccountreview_list");
		return super.getDetail(request, response, model);
		
	}
	
	/**
	 * 获取会员信息Json数据
	 * @param request
	 * @param response
	 * @param pagination
	 * @param memReviewEntity
	 * @return
	 */
	@RequestMapping("/getAccountReviewListJson.do")
	@ResponseBody
	public Map getAccountReviewListJson(HttpServletRequest request, HttpServletResponse response,
			Pagination pagination,MemReviewEntity memReviewEntity){
		return settleAccountService.getAccountReviewList(pagination,request,memReviewEntity);
	}
	
	/**
	 * 获取会员结算信息详情
	 * @param request
	 * @param response
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/getReviewAccInfo.do")
	public ModelAndView getReviewAccInfo(HttpServletRequest request, HttpServletResponse response, String bankcard_uuid){
		ModelAndView model = new ModelAndView("/module/review/settleaccountreview/settleaccount_review");
		Map app_Custom_InfEntity = customBankcardInfoService.getCustomUUIDByUUID(bankcard_uuid);
		model.addObject("custom_uuid",app_Custom_InfEntity.get("custom_uuid"));
		model.addObject("bankcard_uuid",bankcard_uuid);
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 获取会员结算相关信息
	 * @param request
	 * @param response
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/getCommonAccInfo.do")
	public ModelAndView getCommonAccInfo(HttpServletRequest request, HttpServletResponse response, String bankcard_uuid){
		ModelAndView model = new ModelAndView("/module/review/settleaccountreview/settleaccount_common_detail");
		
		if(!StringUtils.isEmpty(bankcard_uuid)){
			Map app_Custom_InfEntity = customBankcardInfoService.getCustomUUIDByUUID(bankcard_uuid);
			String custom_uuid = (String) app_Custom_InfEntity.get("custom_uuid");
			Map customInfEntity = appCustomerInfoService.getCustomerInfoByUUID(custom_uuid);
			Map appCustomBankOldEntity = customBankcardInfoService.getOldCustomBankcardInfo(bankcard_uuid);
			Map appCustomBankNewEntity = customBankcardInfoService.getNewestCustomBankcardInfo(bankcard_uuid);
			List<Map<String, Object>> oldPicList = appAffixInfService.getCustomCertificatePic(custom_uuid);
			List<Map<String, Object>> newPicList = appAffixInfService.getCustomCertificateNewPic(custom_uuid);
			
			model.addObject("customInfEntity",customInfEntity);
			model.addObject("appCustomBankOldEntity",appCustomBankOldEntity);
			model.addObject("appCustomBankNewEntity",appCustomBankNewEntity);
			model.addObject("oldPicList",oldPicList);
			model.addObject("newPicList",newPicList);
		}
		
		return super.getDetail(request, response, model);
	}
	
	@RequestMapping("/getReviewAccDoneInfo.do")
	public ModelAndView getReviewAccDoneInfo(HttpServletRequest request, HttpServletResponse response, String bankcard_uuid){
		
		ModelAndView model = new ModelAndView("/module/review/settleaccountreview/settleaccount_detail");
		Map app_Custom_InfEntity = customBankcardInfoService.getCustomUUIDByUUID(bankcard_uuid);
		model.addObject("custom_uuid",app_Custom_InfEntity.get("custom_uuid"));
		model.addObject("bankcard_uuid",bankcard_uuid);
		
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 审核通过操作
	 * @param request
	 * @param response
	 * @param audit_comments
	 * @param custom_uuid
	 * @param bankcard_uuid
	 * @return
	 */
	@RequestMapping("/accountReviewPass.do")
	public ModelAndView accountReviewPass(HttpServletRequest request, HttpServletResponse response,String audit_comments,String bankcard_uuid){
		
		Map map=super.getLoginUser(request, response);
		settleAccountService.accountReviewPass(audit_comments,bankcard_uuid,map);
		return new ModelAndView(new RedirectView("getSettleAccountReviewList.do"), map);
	}
	
	/**
	 * 退回修改操作
	 * @param request
	 * @param response
	 * @param audit_comments
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/accountReviewBack.do")
	public ModelAndView accountReviewBack(HttpServletRequest request, HttpServletResponse response,String audit_comments,String bankcard_uuid){
		
		Map map=super.getLoginUser(request, response);
		settleAccountService.accountReviewBack(audit_comments,bankcard_uuid,map);
		return new ModelAndView(new RedirectView("getSettleAccountReviewList.do"), map);
	}
	
	@RequestMapping("/checkBankcard.do")
	@ResponseBody
	public String checkBankcard(String bankcard_uuid){
		
		return settleAccountService.checkBankcardInfo(bankcard_uuid);
	}
	
	/**
	 * 获取原结算卡图片信息
	 * @param custom_uuid
	 * @return
	 */
	@RequestMapping("/showOldPicInfo.do")
	public ModelAndView showOldPicInfo(HttpServletRequest request, HttpServletResponse response, String custom_uuid, String picId){
		ModelAndView modelAndView = new ModelAndView("/module/review/settleaccountreview/settleaccountinfo_oldpic_detail");
		if(!StringUtils.isEmpty(custom_uuid)){
			List<Map<String, Object>> picList = appAffixInfService.getCustomCertificatePic(custom_uuid);
			modelAndView.addObject("picList", picList);
			modelAndView.addObject("picId", picId);
		}
		return super.getDetail(request, response, modelAndView);
	}
	
	/**
	 * 获取变更的结算卡图片信息
	 * @param request
	 * @param response
	 * @param custom_uuid
	 * @param picId
	 * @return
	 */
	@RequestMapping("/showNewPicInfo.do")
	public ModelAndView showNewPicInfo(HttpServletRequest request, HttpServletResponse response, String custom_uuid, String picId){
		ModelAndView modelAndView = new ModelAndView("/module/review/settleaccountreview/settleaccountinfo_newpic_detail");
		if(!StringUtils.isEmpty(custom_uuid)){
			List<Map<String, Object>> picList = appAffixInfService.getCustomCertificateNewPic(custom_uuid);
			modelAndView.addObject("picList", picList);
			modelAndView.addObject("picId", picId);
		}
		return super.getDetail(request, response, modelAndView);
	}

}
